package cn.kailangtu.dataspot.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import cn.kailangtu.dataspot.R;
import cn.kailangtu.dataspot.data.ExceptionData;

public class ExceptionLogAdapter2 extends ArrayAdapter {
    private Context context;
    private LayoutInflater flater;
    private List<ExceptionData> data;


    public ExceptionLogAdapter2(Context context, int resource, List<ExceptionData> data) {
        super(context, resource, data);
        this.context = context;
        this.data = data;
        flater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ExceptionData item = data.get(position);
        if (convertView == null) {
            //通过flater获取lis行对象
            convertView = flater.inflate(R.layout.item_exception_log_data, parent, false);
        }

        TextView tvLogId = convertView.findViewById(R.id.tvExceptionLogId);
        TextView tvLogTime = convertView.findViewById(R.id.tvExceptionLogTime);
        TextView tvLogContent = convertView.findViewById(R.id.tvExceptionLogContent);

        tvLogId.setText(String.valueOf(item.getLogId()));
        tvLogTime.setText(item.getLogTimeString());
        tvLogContent.setText(item.getLogContent());

        return convertView;
    }

}
